<template>
    <div class="main">
        <panel class="panel" :list="list" type="1"></panel>
        <button class="dis-b loadMore" v-if="moreData" @click="loadMore">点击查看更多</button>
        <no-data v-if="noData"></no-data>
        <toast v-model="toast" type="text" :time="1000" is-show-mask :text="text" position="default"></toast>
    </div>
</template>

<script>
    import util from "../../fetch/util";
    import {Panel} from 'vux'

    export default {
        name: "member",
        components: {
            Panel,
        },
        data: function () {
            return {
                headTxt: '',
                noData: true,
                toast: false,
                text: '',
                list: [],
                pageId: 0,
                last_page: 0,
                moreData: false,
            }
        },
        methods: {
            getData(pageId) {
                let type = this.$route.query.type, url;
                let userInfo = JSON.parse(localStorage.getItem('userInfo'));
                let params = {
                    id: userInfo.id,
                    current_page: pageId,
                };
                if (type === 'gold') {
                    url = 'scanUsers';
                    params.type = 1;
                } else if (type === 'gem') {
                    url = 'gemUsersg';
                    params.type = 0;
                } else {
                    this.text = '参数错误，请重新登陆';
                    this.toast = true;
                    setTimeout(() => {
                        localStorage.clear();
                        this.$router.push({
                            name: 'login'
                        });
                    }, 1000);
                    return false;
                }
                util.fetchGet(util.path[url], params).then((data) => {
                    if (data.code === 0) {
                        let thisData = data.data,
                             dataList = thisData.data;
                        if(thisData.total <= 0){
                            this.noData = true;
                            this.moreData = false;
                        } else {
                            this.noData = false;
                            this.moreData = true;
                            this.last_page = thisData.last_page;
                            if(thisData.total < 10 || dataList.length < 10){
                                this.moreData = false;
                            }
                            for (let i = 0; i < dataList.length; i++) {
                                this.list.push({
                                    src: dataList[i].imgurl,
                                    title: dataList[i].nickname + ` <span style="font-size: 12px;margin-left: 10px;">${dataList[i].id == 0 ? '未登入' : 'id :' + dataList[i].id}</span>`,
                                    desc: `加入时间: ${dataList[i].regtime} `
                                })
                            }
                        }
                    } else {
                        console.log(data);
                    }
                })
            },
            loadMore() {
                this.pageId++;
                this.getData(this.pageId);
            },
        },
        mounted: function () {
            this.getData(this.pageId);
        }
    }
</script>

<style scoped>
    .panel {
        margin-top: 0 !important;
    }
</style>
